from sqlalchemy import ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column, relationship

from ...core.models.enums.withdraw import WithdrawStatus
from .base import TimedBaseModel


class Withdraw(TimedBaseModel):
    __tablename__ = "withdraw"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    summ: Mapped[float]
    status: Mapped[WithdrawStatus] = mapped_column(server_default="on_moderation")
    payment_method = relationship("PaymentDetails", back_populates="withdrawals")
    payment_method_id: Mapped[int] = mapped_column(
        ForeignKey("payment_details.id"), nullable=True
    )
    payment_address: Mapped[str] = mapped_column(String(255))
    user = relationship("User", back_populates="withdrawals")
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))

    def __repr__(self):
        return f"<Запрос на вывод №{self.id} {self.summ}>"

    def __str__(self):
        return self.__repr__()
